
"""测试框架功能"""

import wx
import os
import wx.lib.buttons as buttons


class CustomDialog(wx.Dialog):
    """一个自定义的dialog, 样式布局等等的自定义"""
    def __init__(self):
        wx.Dialog.__init__(self, None, -1, "Custom Subclass", size=(300, 100))
        okButton = buttons.GenButton(self, wx.ID_OK, "确定", (15, 15))
        okButton.SetDefault()
        cancleButton = buttons.GenButton(self, wx.ID_CANCEL, "取消", (115, 15))
        cancleButton.SetDefault()


class DialogFrame(wx.Frame):
    """一个自定义框架"""
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Custom Frame", (500, 400))
        self.panel = wx.Panel(self, -1)
        self.configUI()

    def configUI(self):
        customDlgBtn = buttons.GenButton(self, -1, "自定义对话框", (10, 10), (100, 30))
        self.Bind(wx.EVT_BUTTON, self.onCustomDialog, customDlgBtn)
        #警告框
        warnDlgBtn = buttons.GenButton(self, -1, "警告框", (120, 10), (100, 30))
        self.Bind(wx.EVT_BUTTON, self.onWarningDialog, warnDlgBtn)
        #文本输入框
        textDlgBtn = buttons.GenButton(self, -1, "文本输入框", (230, 10), (100, 30))
        self.Bind(wx.EVT_BUTTON, self.onTextDialog, textDlgBtn)
        # 文本输入框
        listDlgBtn = buttons.GenButton(self, -1, "列表选择框", (10, 50), (100, 30))
        self.Bind(wx.EVT_BUTTON, self.onListDialog, listDlgBtn)
        # 进度条
        progressDlgBtn = buttons.GenButton(self, -1, "进度条", (120, 50), (100, 30))
        self.Bind(wx.EVT_BUTTON, self.onProgressDialog, progressDlgBtn)
        # 文件对话框
        fileDlgBtn = buttons.GenButton(self, -1, "文件对话框", (230, 50), (100, 30))
        self.Bind(wx.EVT_BUTTON, self.onFileDialog, fileDlgBtn)

    def onCustomDialog(self, e):
        customDialog = CustomDialog()
        result = customDialog.ShowModal()
        if result == wx.ID_OK:
            print("确定")
        else:
            print("取消")
        customDialog.Destroy()

    def onWarningDialog(self, e):
        """展示一个警告框"""
        #第一种方法
        warningDlg = wx.MessageDialog(None, "您将提现230.20元, 操作不可撤回, 是否确定?", "警告!!!", style=wx.YES_NO|wx.ICON_WARNING)
        result = warningDlg.ShowModal()
        print(result)
        #第二种方法
        rlt = wx.MessageBox("支付30000元, 是否确定?", "温馨提示", style=wx.YES_NO|wx.ICON_QUESTION)
        print(rlt)

    def onTextDialog(self, e):
        """文本输入框"""
        dialog = wx.TextEntryDialog(None, "Enter Your Name","Text Entry”", "Default Value", style = wx.OK | wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            print(dialog.GetValue())
        dialog.Destroy()

    def onListDialog(self, e):
        list = ["wdf", "zlz", "syz", "rxy", "yhx", "lml"]
        listDialog = wx.SingleChoiceDialog(None, "选择你要杀掉的人", "狼人游戏", list)
        listDialog.ShowModal()
        print(listDialog.GetStringSelection())

    def onProgressDialog(self, e):
        """进度条"""
        dialog = wx.ProgressDialog("进度条标题", "上传进度", 100, None, style=wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME)
        keepGoing = True
        count = 0
        while keepGoing and count < 100:
            count = count + 1
            wx.Sleep(1)
            keepGoing = dialog.Update(count)

    def onFileDialog(self, e):
        """弹出一个选择文件的对话框"""
        wildcard = "Python sourse(*.py)|*.py|*.png|*.jpg|*.jpeg"
        dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), "",wildcard, wx.FD_SAVE)
        if dialog.ShowModal() == wx.ID_OK:
            print(dialog.GetPath())
        else:
            print("cancle")
        dialog.Destroy()



    def onCloseWindow(self, e):
        print("onCloseWindow")
        self.Destroy()
        pass


def customFrameDemo():
    app = wx.App()
    frame = DialogFrame()
    frame.Show(True)
    app.MainLoop()

if __name__ == "__main__":
    customFrameDemo()





